/**
  ETFRoot project, Anyang Normal University && IMP-CAS
  \class ETFDC
  \brief for DCs downstream the dipole magnet
  \author SUN Yazhou, asia.rabbit@163.com
  \since 2021-10-28
  \date 2021-12-09 last modified
  \attention
  changelog
  <table>
  <tr>  <th>Date         <th>Author      <th>Description                   </tr>
  <tr>  <td>2021-10-28   <td>Asia Sun    <td>file created                  </tr>
  </table>

  \copyright Copyright (c) 2021 Anyang Normal U. && IMP-CAS with LGPLv3 LICENSE
*/

#ifndef ETFDC_h
#define ETFDC_h

#include "ETFVDC.h"

class TClonesArray;

class ETFDC : public ETFVDC{
public:
  ETFDC(){}
  ETFDC(const char *name);
  virtual ~ETFDC();

  virtual void Initialize(); ///< initialize the detector
  /// add the data channel to the detector
  virtual void Assign(const ETFHPTDCChannel *ch);
  virtual void ConstructGraph(); ///< add sigle wires to fGDumb
  virtual void DrawHits(); ///< draw the hits
  /// set the wire's projection to its normal plane
  virtual void SetHitProjection(ETFDCHit *h, DCType typeDC);
  virtual void Register(); ///< register hits to the main output tree

  /// get the fired sense wire layer
  /// \param type: XUV or XY, DC type; x12: X1 or X2
  virtual TClonesArray *GetHitsArray(DCType typeDC, int x12);
  virtual void Print(); ///< print the detector info

  /// r = r(t); drift distance - drift time relation
  virtual double SpaceTimeRelation(double t);
  /// \retval false: if obtained drift time out of range
  /// NOTE that if trk has non-FitStatus::kUNFITTED FitStatus, this method
  /// would do nothing, as drift distance only changes with drift time,
  /// whose changes would ensure fFitStatus be set to FitStatus::kUNFITTED
  virtual bool SetDriftDistance(ETFVTrack *trk);
  void SetPhiAvrg(double p){ fPhiAvrg = p; }

  ClassDef(ETFDC, 1);

protected:
  /// \param wireId: 0-159, along x increasing direction
  /// \param type: 0-1-2: X-U-V or X-Y--
  virtual void AddHit(const ETFHPTDCChannel *ch, int wireId, DCType typeDC);
  /// fill channel map for a 32-ch LVDS cable
  virtual void FillCableChMap(int chId0);

  /// the six layers of fired sense wires
  TClonesArray *fHits[3][2]; //-> ///< [xuv][x1-x2]
  /// uid prefix, just for generation of UID
  /// definition of UID: [0-7]: detId; [8-9]: X-U-V; [10]: X1-X2; [11-17]: wireId
  unsigned type[3]; ///< XUVY, X1-X2, [cableId]
  double fPhiAvrg; ///< the average phi of DC0-1-2, used to calculate wire projections
};

#endif
